import { renderTableText, tableSorter, tooltipLength } from '@/utils';
import { Button, Tooltip } from 'antd';
import pageStyles from '@/common/pageLayout.less';
import { EyeOutlined, ProjectOutlined, MonitorOutlined, ContainerOutlined } from '@ant-design/icons';
// import { ApplyHomeAPI } from '../common/type';
import { IntentHomeAPI } from '../common/type';

/**
 * 返回表格配置
 * @param taskType true:待办   false:已办
 * @returns
 */
const getHomeTableColumns = (curRes: Record<string, any>, taskType: boolean, onOptClick: IntentHomeAPI.IOperationClick) => {
  let columns: Record<string, any>[] = [
    {
      title: '事项名称',
      dataIndex: 'busi_purchProjectName',
      key: 'busi_purchProjectName',
      width: 160,
      visible: 'allTask',
      fixed: 'left',
      // sorter: (a: any, b: any) => (a?.attributes.busi_purchProjectName > b?.attributes.busi_purchProjectName ? 1 : -1),
      // render: (text: string | null, record: Record<string, any>) => {
      //   const showText: string | null = record?.attributes?.busi_purchProjectName;
      //   return (
      //     <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
      //       <span className={pageStyles['over-flow-hidden']}>
      //         <a
      //           onClick={() => {
      //             onOptClick?.onView(record);
      //           }}
      //         >
      //           {showText ? showText : '--'}
      //         </a>
      //       </span>
      //     </Tooltip>
      //   );
      // },
    },
    {
      title: '类型',
      dataIndex: 'busi_changeWay',
      key: 'busi_changeWay',
      width: 100,
      visible: 'allTask',
      // sorter: (a: any, b: any) => (a?.attributes.busi_changeWay > b?.attributes.busi_changeWay ? 1 : -1),
      // render: (text: string | null, record: Record<string, any>) => {
      //   const changeWay: string | null = record?.attributes.busi_changeWay;
      //   let showText: string = '意向公开申请';
      //   return (
      //     <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
      //       <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
      //     </Tooltip>
      //   );
      // },
    },
    {
      title: '当前环节',
      dataIndex: 'taskName',
      key: 'taskName',
      visible: 'allTask',
      width: 170,
      // sorter: (a: any, b: any) => tableSorter(a, b, 'taskName'),
      // render: (text: string) => renderTableText(text, true),
    },
    {
      title: '时间',
      dataIndex: 'createTime',
      key: 'createTime',
      width: 160,
      visible: 'notTask',
      // sorter: (a: any, b: any) => tableSorter(a, b, 'createTime'),
      // render: (text: string, record: Record<string, any>) => {
      //   return (
      //     <Tooltip title={text ? text : ''}>
      //       <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
      //     </Tooltip>
      //   );
      // },
    },
    {
      title: '发送人',
      dataIndex: 'busi_applyerName',
      key: 'busi_applyerName',
      width: 100,
      visible: 'notTask',
      // sorter: (a: any, b: any) => (a?.attributes.busi_applyerName > b?.attributes.busi_applyerName ? 1 : -1),
      // render: (text: string | null, record: Record<string, any>) => {
      //   const showText: string | null = record?.attributes.busi_applyerName;
      //   return (
      //     <Tooltip title={showText ? tooltipLength(showText, 50) : ''}>
      //       <span className={pageStyles['over-flow-hidden']}>{showText ? showText : '--'}</span>
      //     </Tooltip>
      //   );
      // },
    },
    // {
    //   title: '办理时间',
    //   dataIndex: 'endTime',
    //   key: 'endTime',
    //   width: 160,
    //   visible: 'handTask',
    //   sorter: (a: any, b: any) => tableSorter(a, b, 'endTime'),
    //   render: (text: string, record: Record<string, any>) => {
    //     return (
    //       <Tooltip title={text ? text : ''}>
    //         <span className={pageStyles['over-flow-hidden']}>{text ? text : '--'}</span>
    //       </Tooltip>
    //     );
    //   },
    // },
    // {
    //   title: '办理人',
    //   dataIndex: 'assigneeName',
    //   key: 'assigneeName',
    //   width: 100,
    //   visible: 'handTask',
    //   sorter: (a: any, b: any) => (a?.assigneeName > b?.assigneeName ? 1 : -1),
    //   render: (text: string) => renderTableText(text, true),
    // },
    // {
    //   title: '办理结果',
    //   dataIndex: 'resultInfo',
    //   key: 'resultInfo',
    //   width: 115,
    //   visible: 'handTask',
    //   sorter: (a: any, b: any) => (a?.resultInfo > b?.resultInfo ? 1 : -1),
    //   render: (text: string) => renderTableText(text, true),
    // },
    {
      title: '操作',
      dataIndex: 'operation',
      key: 'operation',
      width: 130,
      visible: true,
      fixed: 'right',
      render: (_text: any, record: any) => {
        return (
          <div
            style={{
              display: 'flex',
            }}
          >
            <Button
              className="manageBtntTxtStyle"
              onClick={() => {
                // onOptClick?.onHand(record);
              }}
              type={'link'}
              icon={<ContainerOutlined />}
            >
              OA
            </Button>
            <Button
              className="manageBtntTxtStyle"
              onClick={() => {
                // onOptClick?.onHand(record);
              }}
              type={'link'}
              icon={<ProjectOutlined />}
            >
              办理
            </Button>
          </div>
        );
      },
    },
  ];

  columns = columns?.filter((item: any) => (taskType ? item?.visible != 'handTask' : item?.visible != 'notTask'));

  return columns;
};

export { getHomeTableColumns };
